package com.whfc.wxmp.api.quality.controller;

import com.whfc.common.base.BaseController;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.wxmp.annotation.CurrentWxUser;
import com.whfc.fuum.entity.WxUser;
import com.whfc.quality.dto.QualityAcceptanceDTO;
import com.whfc.quality.param.QualityAcceptanceAddParam;
import com.whfc.quality.param.QualityAcceptanceEditParam;
import com.whfc.wxmp.api.quality.service.WxQualityAcceptanceService;
import com.whfc.wxmp.util.RequestConetxtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author: hw
 * @date: 2021-10-30 9:21
 * @description: 验收情况
 */
@RestController
@RequestMapping("/mp/api/quality/acceptance")
public class WxQualityAcceptanceController extends BaseController {

    @Autowired
    private WxQualityAcceptanceService wxQualityAcceptanceService;


    @PostMapping("/add")
    public Result add(@CurrentWxUser WxUser user, @Validated @RequestBody QualityAcceptanceAddParam param) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                user.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "新增验收情况", RequestConetxtUtil.getParameters());
        wxQualityAcceptanceService.add(param);
        return ResultUtil.success();
    }

    @PostMapping("/edit")
    public Result edit(@CurrentWxUser WxUser user, @Validated @RequestBody QualityAcceptanceEditParam param) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                user.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "修改验收情况", RequestConetxtUtil.getParameters());
        wxQualityAcceptanceService.edit(param);
        return ResultUtil.success();
    }

    @GetMapping("details")
    public Result details(@CurrentWxUser WxUser user, @RequestParam("deptId") Integer deptId,
                          @RequestParam(value = "time", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date time) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                user.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "验收情况详情", RequestConetxtUtil.getParameters());
        QualityAcceptanceDTO data = wxQualityAcceptanceService.details(deptId, time);
        return ResultUtil.success(data);
    }

}
